package com.entmanage.base.achievement.controller;

import com.entmanage.base.achievement.domain.AchievementCases;
import com.entmanage.base.achievement.service.IAchievementCasesService;
import com.entmanage.common.annotation.Anonymous;
import com.entmanage.common.annotation.DataScope;
import io.swagger.annotations.Api;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.entmanage.common.annotation.Log;
import com.entmanage.common.core.controller.BaseController;
import com.entmanage.common.core.domain.AjaxResult;
import com.entmanage.common.enums.BusinessType;
import com.entmanage.common.utils.poi.ExcelUtil;
import com.entmanage.common.core.page.TableDataInfo;

/**
 * 成果展示案例Controller
 *
 * @author lsq
 * @date 2025-08-22
 */
@Api(tags = {"achievement-AchievementCases模块"}, description = "成果展示案例")
@RestController
@RequestMapping("/achievement/cases")
public class AchievementCasesController extends BaseController
{
    @Autowired
    private IAchievementCasesService achievementCasesService;

    /**
     * 查询成果展示案例列表
     */

    @PreAuthorize("@ss.hasPermi('achievement:cases:list')")
    @GetMapping("/list")
    @DataScope(deptAlias = "d", userAlias = "u")
    public TableDataInfo list(AchievementCases achievementCases)
    {
        startPage();
        List<AchievementCases> list = achievementCasesService.selectAchievementCasesList(achievementCases);
        return getDataTable(list);
    }

    /**
     * 导出成果展示案例列表
     */
    @PreAuthorize("@ss.hasPermi('achievement:cases:export')")
    @Log(title = "成果展示案例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AchievementCases achievementCases)
    {
        List<AchievementCases> list = achievementCasesService.selectAchievementCasesList(achievementCases);
        ExcelUtil<AchievementCases> util = new ExcelUtil<AchievementCases>(AchievementCases.class);
        util.exportExcel(response, list, "成果展示案例数据");
    }

    /**
     * 获取成果展示案例详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('achievement:cases:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(achievementCasesService.selectAchievementCasesById(id));
    }

    /**
     * 新增成果展示案例
     */
    @PreAuthorize("@ss.hasPermi('achievement:cases:add')")
    @Log(title = "成果展示案例", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AchievementCases achievementCases)
    {
        return toAjax(achievementCasesService.insertAchievementCases(achievementCases));
    }

    /**
     * 修改成果展示案例
     */
    @PreAuthorize("@ss.hasPermi('achievement:cases:edit')")
    @Log(title = "成果展示案例", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AchievementCases achievementCases)
    {
        return toAjax(achievementCasesService.updateAchievementCases(achievementCases));
    }

    /**
     * 删除成果展示案例
     */
    @PreAuthorize("@ss.hasPermi('achievement:cases:remove')")
    @Log(title = "成果展示案例", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(achievementCasesService.deleteAchievementCasesByIds(ids));
    }

    /**
     * 修改案例发布状态
     */
    @PreAuthorize("@ss.hasPermi('achievement:cases:edit')")
    @Log(title = "成果展示案例", businessType = BusinessType.UPDATE)
    @PostMapping("/publish")
    public AjaxResult changePublishStatus(
            @RequestParam Long id,
            @RequestParam Integer isPublished
    ) {
        AchievementCases cases = new AchievementCases();
        cases.setId(id);
        cases.setIsPublished(isPublished);
        return toAjax(achievementCasesService.updateAchievementCases(cases));
    }

    /**
     * 修改精选状态
     */
    @PreAuthorize("@ss.hasPermi('achievement:cases:edit')")
    @Log(title = "成果展示案例", businessType = BusinessType.UPDATE)
    @PostMapping("/featured")
    public AjaxResult changeFeaturedStatus(
            @RequestParam Long id,
            @RequestParam Integer isFeatured
    ) {
        AchievementCases cases = new AchievementCases();
        cases.setId(id);
        cases.setIsFeatured(isFeatured);
        return toAjax(achievementCasesService.updateAchievementCases(cases));
    }


    /**
     * 查询成果展示案例列表（用于官网展示，跳过拦截器）
     */
    @GetMapping("/homeList")
    public TableDataInfo homeList(AchievementCases achievementCases)
    {
        startPage();
        List<AchievementCases> list = achievementCasesService.selectAchievementCasesList(achievementCases);
        return getDataTable(list);
    }



}
